//
//  Unity.swift
//  Pods
//
//  Created by HongPu on 2015/8/3.
//
//

import Foundation

public final class Box<U>
{
    let value: U
    public init(value: U)
    {
        self.value = value
    }
}

public enum Result<T>
{
    case Success(Box<T>)
    case Error(NSError)
    
    public func handleTrackError<U>(handle: (T) -> Result<U>) -> Result<U>
    {
        switch self
        {
        case .Error(let error):
            return .Error(error)
            
        case .Success(let box):
            return handle(box.value)
        }
    }
}


func runCauseError(reason: String = "")
{
    #if DEBUG
        println("===FATAL ERROR: \(reason) ===\nfile name: \(__FILE__)\nfunc name: \(__FUNCTION__)\nline no: \(__LINE__)\ncolumn no: \(__COLUMN__)\n======")
    #endif
}

func printError(error: NSError)
{
    #if DEBUG
        println("--- ERROR: \(error.localizedDescription) ---")
    #endif
}